$(function(){
    $('#selectedCoursesTable').bootstrapTable({
        url: '/Salary/ViewSalary',
        method: 'post',
        showRefresh: true,  //显示刷新按钮
        search: true,
        toolbar:'#toolbar',
        striped : true,     //设置为true会有隔行变色效果
        //sidePagination:'server',//服务器端分页默认接受rows和total
        pagination:true,//客户端分页
        sidePagination:'client',
        idFiled:'studentSelectCourseId',
        pageNumber:1,
        pageSize:10,
        columns: [
            {
                field: 'checkId',
                checkbox:true,
                clickToSelect:true,
            },
            {
                field: 'institution_id',
                title: '机构id',
            },{
                field: 'name',
                title: '机构名'
            }
            , {
                field: 'position_id',
                title: '岗位ID'
            },{
                field: 'posName',
                title: '岗位名'
            },
            {
                field: 'salary',
                title: '薪资'
            }]
    });
});

var vm  = new Vue({
    el:'#studentSelectCourse',
    data:{
    showList: 1,
        positionInf:'',
    },
    methods:{
      //修改底薪
        add:function() {
            // 获取下拉列表所选的value
           var rows = $("#selectedCoursesTable").bootstrapTable('getSelections');
           if(rows.length == 0){
               layer.alert('请选择至少一条记录');
           }else {
               //弹出修改底薪按钮
               $('#selectCourseDialog').modal("show");
           //遍历选择所选行的数据，取得每条数据对应的id
            var ids = new Array();
            var names = new Array();
            var valets='';
           $.each(rows,function (i,row) {
               ids[i] = row['position_id'];
               names[i] = row['posName'];
               valets += (names[i]+':'+ids[i]+',');
           });
           vm.positionInf = valets;
           //回显薪资下拉框
               $("#baseSalary").empty();
               var optionName="请点击选择底薪";
               $.ajax({
                   type:"POST",
                   url:"/Salary/BSalary",
                   success:function (result) {
                       $("#baseSalary").append("<option value=" +   ">" + optionName + "</option>")
                       for(var i =0;i<result.length;i++){
                           $("#baseSalary").append("<option name='sb' value="+result[i].salaryId + ">" +result[i].salary + "</option>");
                       }

                   }
               })
        };

    },

    submit:function () {
        var rows = $("#selectedCoursesTable").bootstrapTable('getSelections');
        var ids = new Array();
        $.each(rows,function (i,row) {
            ids[i] = row['position_id'];
        });
        var salaryid = $("#baseSalary option:selected").val();
        var pid = ids;
        var data = {"id":pid,"salaryid":salaryid};
        console.log(data);
        $.ajax({
            type:"POST",
            url: '/Salary/SetBaseSalary',
            data: JSON.stringify(data),
            success:function (r) {
                if(r.code == 0){
                    layer.alert('修改底薪成功');
                    //删除下拉框中当前选中的元素
                    $("#baseSalary option:selected").remove();
                    $("#selectedCoursesTable").bootstrapTable('refresh');

                }
            },
            error:function () {
                layer.alert('服务器没有返回数据');
            }
        });

    }



    }});